//
//  MYXHttpManager.m
//  meiyinxiang
//
//  Created by 陈李飞 on 2017/11/21.
//  Copyright © 2017年 hbjApple. All rights reserved.
//

#import "MYXHttpManager.h"


#import "myfollowListModel.h"
#import "myfanslistModel.h"
#import "MYXAuthenticationModel.h"
#import "MYXrandtagsModel.h"
#import "MYX_Bossshouyi_listModel.h"
#import "MYXfindmatchModel.h"
#import "MYXotheruserinfoModel.h"
#import "TopHotestModel.h"
#import <AlipaySDK/AlipaySDK.h>
#import "MYXmypublishModel.h"
#import "VocherModel.h"
#import "MYCmymoneylogModel.h"
#import "MYXmymoneyModel.h"
#import "MYXVoteModel.h"
#import "CommentModel.h"
#import "MYXotherinfoListModel.h"
#import "NoticeModel.h"


@implementation MYXHttpManager
+ (MYXHttpManager *)shared{
   static  MYXHttpManager *Instance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        Instance = [[self alloc] init];
    });
    return Instance;
}
- (void)login:(NSString *)account code:(NSString *)code Invitation:(NSString *)Invitation password:(NSString *)password sex:(NSString *)sex success:(void(^)(MYY_User *user))success failure:(void(^)(NSString *  errorCode))failure netDown:(void(^)())netDown{
    NSDictionary *params;
  
        params= @{
                  @"phone" : account,
                  @"password" : password,
                  };
    [[Http sharedInstance] uploadDataWithUrl:MYY_login_URL withParams:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        [formData appendPartWithFormData:[account dataUsingEncoding:NSUTF8StringEncoding]name:@"phone"];
        [formData appendPartWithFormData:[password dataUsingEncoding:NSUTF8StringEncoding]name:@"password"];
    } completion:^(id data, NSError *error) {
        int  nRet = [[data objectForKey:@"status"] intValue];
        if (nRet == 1) {
            MYY_User *userd = [[MYY_User alloc]init];
            userd.token             = data[@"data"][@"token"];
            userd.imtoken             = data[@"data"][@"imtoken"];
            userd.accid             = data[@"data"][@"accid"];
            userd.uid             = data[@"data"][@"uid"];
            userd.isLogin = YES;
            [userd save];
            success(userd);
        }else{
        failure( @"登陆出错");
        
        }}];
    
    
}
/* 注册接口*/
- (void)registeraccount:(NSString *)account
                   code:(NSString *)code
             Invitation:(NSString *)Invitation
               password:(NSString *)password
                    sex:(NSString *)sex
                success:(void(^)(MYY_User *user))success
                failure:(void(^)(NSString *  errorCode))failure
                netDown:(void(^)())netDown{
    NSDictionary *params;
   NSString *mInvitation = @"";
    if (Invitation.length > 0) {
        mInvitation = Invitation;
    }
        params= @{
                  @"phone" : account,
                  @"password" : password,
                  @"code" : code,
                  @"sex":sex,
                  @"fphone":mInvitation
                  };

    [[Http sharedInstance] uploadDataWithUrl:MYY_Register_URL withParams:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        [formData appendPartWithFormData:[account dataUsingEncoding:NSUTF8StringEncoding]name:@"phone"];
        [formData appendPartWithFormData:[password dataUsingEncoding:NSUTF8StringEncoding]name:@"password"];
        [formData appendPartWithFormData:[code dataUsingEncoding:NSUTF8StringEncoding]name:@"code"];
        [formData appendPartWithFormData:[sex dataUsingEncoding:NSUTF8StringEncoding]name:@"sex"];
        [formData appendPartWithFormData:[mInvitation dataUsingEncoding:NSUTF8StringEncoding]name:@"fphone"];

    } completion:^(id data, NSError *error) {
        int  nRet = [[data objectForKey:@"status"] intValue];
        if (nRet == 1) {
            MYY_User *userd = [[MYY_User alloc]init];
            userd.token             = data[@"data"][@"token"];
            userd.imtoken             = data[@"data"][@"imtoken"];
            userd.accid             = data[@"data"][@"accid"];
            userd.uid             = data[@"data"][@"uid"];
            userd.isLogin = YES;
            [userd save];
            success(userd);
        }else{
            failure( @"登陆出错");
            
        }}];
}
- (void)userinfo:(void(^)(MYXMemberMdel *user))success failure:(void(^)(NSString *  errorCode))failure netDown:(void(^)())netDown{
    [[Http sharedInstance] requestForMethod:GET Url:MYY_userinfo_URL withParams:nil completion:^(id data, NSError *error) {
        if (data) {
            
            int  nRet = [[data objectForKey:@"status"] intValue];
            NSString *dataStr;
            
            if (nRet == 1) {
                /*
                 @property (copy,nonatomic)  NSString * fanscount;
                @property (copy,nonatomic)  NSString * followscount;
                @property(nonatomic, copy)  NSString *visits;
                @property (strong,nonatomic) userinfoModel * userinfo;
                @property(nonatomic, copy)  NSString *is_idauth;
                 */
             MYXMemberMdel *userd = [MYXMemberMdel mj_objectWithKeyValues:data[@"data"]];
                userd.userinfo.image = [NSString stringWithFormat:@"%@%@",MYXIMGBaseUrl,userd.userinfo.image];
                MYXMemberMdel *model = [MYXMemberMdel sharedInstance];
                model.userinfo = userd.userinfo;
                model.fanscount = userd.fanscount;
                model.visits = userd.visits;
                model.is_idauth = userd.is_idauth;
                model.followscount = userd.followscount;
                [model save];
                [userd save];
              BOOL isSucess =  [model save];;
                if (isSucess) {
                    success(userd);

                }else{
                    success(nil);
                }
            }
            else {
                dataStr= [data objectForKey:@"message"];
                failure( dataStr);
                
            }
            
        }
        
        
    }];
}

- (void)myfollowList:(void(^)(NSArray *followListArray))success
             failure:(void(^)(NSString *  errorCode))failure
             netDown:(void(^)())netDown
                page:(NSString *)page
                size:(NSString *)size{
    NSDictionary *dicPara = @{
                              @"page":page,
                              @"size":size
                              };
    [[Http sharedInstance] requestForMethod:GET Url:MYX_myfollow_URL withParams:dicPara completion:^(id data, NSError *error) {
        if (data) {
            int  nRet = [[data objectForKey:@"status"] intValue];
            NSString *dataStr;
            NSArray *array;
            if (nRet == 1) {
                
                if((NSNull *)data[@"data"]== [NSNull null])
                {
                    // return;
                }else{
                    array = [myfollowListModel mj_objectArrayWithKeyValuesArray:data[@"data"]];
                }
                success(array);
            }
            else {
                dataStr= [data objectForKey:@"message"];
                failure( dataStr);
                
            }
            
        }
        
        
    }];
}

- (void)myfansList:(void(^)(NSArray *myfansListArray))success
           failure:(void(^)(NSString *  errorCode))failure
           netDown:(void(^)())netDown
              page:(NSString *)page
              size:(NSString *)size{
        NSDictionary *param = @{
                                @"Page":page,
                                @"size":size
                                };
    
    [[Http sharedInstance] requestForMethod:GET Url:MYX_myfans_URL withParams:param completion:^(id data, NSError *error) {
        if (data) {
            
            int  nRet = [[data objectForKey:@"status"] intValue];
            NSString *dataStr;
            NSArray *array;
            if (nRet == 1) {
                
                if((NSNull *)data[@"data"]== [NSNull null])
                {
                    // return;
                }else{
                    array = [myfollowListModel mj_objectArrayWithKeyValuesArray:data[@"data"]];
                }
                success(array);
            }
            else {
                dataStr= [data objectForKey:@"message"];
                failure( dataStr);
                
            }
            
        }
        
        
    }];
    
}
- (void)imreg:(void(^)(NSString  *mes))success failure:(void(^)(NSString *  errorCode))failure netDown:(void(^)())netDown{
    [[Http sharedInstance] requestForMethod:GET Url:MYX_imreg_URL withParams:nil completion:^(id data, NSError *error) {
        if (data) {
            
            int  nRet = [[data objectForKey:@"status"] intValue];
            NSString *dataStr;
            NSArray *array;
            if (nRet == 1) {
                
                success(dataStr);
            }
            else {
                dataStr= [data objectForKey:@"message"];
                failure( dataStr);
                
            }
            
        }
        
        
    }];
}

- (void)useredit:(NSString *)image username:(NSString *)username nickname:(NSString *)nickname sex:(NSString *)sex tags:(NSString *)tags tags2:(NSString *)tags2 age:(NSString *)age home:(NSString *)home birthday:(NSString *)birthday signature:(NSString *)signature success:(void(^)(NSString *dataStr))success failure:(void(^)(NSString *  errorCode))failure netDown:(void(^)())netDown{
    NSDictionary *params = @{
                             @"image" : image != nil ? image : @"",
                             @"username" : username != nil ? username : @"",
                             @"nickname" : nickname != nil ? nickname : @"",
                             @"sex" : sex != nil ? sex : @"",
                             @"tags" : tags != nil ? tags : @"",
                             @"age" : age != nil ? age : @"",
                             @"home" : home != nil ? home : @"",
                             @"birthday" : birthday != nil ? birthday : @"",
                             @"signature" : signature != nil ? signature : @"",
                             };
    [[Http sharedInstance] requestForMethod:POST Url:MYY_useredit_URL withParams:params completion:^(id data, NSError *error) {
        if (data) {
            
            int  nRet = [[data objectForKey:@"status"] intValue];
            NSString *dataStr;
            NSString *dataArrStr=data[@"data"];
            if (nRet == 1) {
                success(dataArrStr);
            }else{
                dataStr= [data objectForKey:@"message"];
                failure( dataStr);
                
            }
            
        }else{
            failure(@"您的提交有误！");
        }
        
        
    }];
    
}

- (void)idauth:(NSString *)real_name code:(NSString *)code image_front:(NSString *)image_front image_back:(NSString *)image_back  success:(void(^)(NSString *dataStr ,MYXAuthenticationModel *MYXAuthenticationMo))success failure:(void(^)(NSString *  errorCode))failure netDown:(void(^)())netDown{
    
    [[Http sharedInstance] uploadDataWithUrl:MYX_idauth_URL withParams:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        [formData appendPartWithFormData:[real_name dataUsingEncoding:NSUTF8StringEncoding]name:@"real_name"];
        [formData appendPartWithFormData:[image_front dataUsingEncoding:NSUTF8StringEncoding]name:@"image_front"];
        [formData appendPartWithFormData:[image_back dataUsingEncoding:NSUTF8StringEncoding]name:@"image_back"];
        [formData appendPartWithFormData:[code dataUsingEncoding:NSUTF8StringEncoding]name:@"code"];
    } completion:^(id data, NSError *error) {
        NSString *dataStr;
        if (data) {
            int  nRet = [[data objectForKey:@"status"] intValue];
            NSString *msg = data[@"message"];
            if (nRet == 1) {
                if ([data[@"data"] isKindOfClass:[NSString class]]) {
                    NSString *dataArrStr=data[@"data"];
                    success(dataArrStr,nil);
                }else{
                    MYXAuthenticationModel *MYXAuthenticationMod = [MYXAuthenticationModel mj_objectWithKeyValues:data[@"data"]];
                    success(msg,MYXAuthenticationMod);
                }
                
            }
            else {
                dataStr= [data objectForKey:@"message"];
                failure( dataStr);
                
            }
            
        }
        
    }];
    
}

- (void)addfollow:(NSString *)addfollow_ID success:(void(^)(NSString *dataStr))success failure:(void(^)(NSString *  errorCode))failure netDown:(void(^)())netDown{
    NSDictionary *params = @{
                             @"id" : addfollow_ID,
                             };
    [[Http sharedInstance] requestForMethod:POST Url:MYX_addfollow_URL withParams:params completion:^(id data, NSError *error) {
        if (data) {
            
            int  nRet = [[data objectForKey:@"status"] intValue];
            NSString *dataStr;
            NSString *dataArrStr=data[@"data"];
            if (nRet == 1) {
                
                success(dataArrStr);
            }
            else {
                dataStr= [data objectForKey:@"message"];
                failure( dataStr);
                
            }
            
        }
        
        
    }];
}

- (void)cancelfollow:(NSString *)follow_ID success:(void(^)(NSString *dataStr))success failure:(void(^)(NSString *  errorCode))failure netDown:(void(^)())netDown{
    NSDictionary *params = @{
                             @"id" : follow_ID,
                             };
    [[Http sharedInstance] requestForMethod:POST Url:MYX_cancelfollow_URL withParams:params completion:^(id data, NSError *error) {
        if (data) {
            
            int  nRet = [[data objectForKey:@"status"] intValue];
            NSString *dataStr;
            NSString *dataArrStr=data[@"data"];
            if (nRet == 1) {
                
                success(dataArrStr);
            }
            else {
                dataStr= [data objectForKey:@"message"];
                failure( dataStr);
                
            }
            
        }
        
        
    }];
}

- (void)identify:(NSString *)iphone_ID success:(void(^)(NSString *dataStr))success failure:(void(^)(NSString *  errorCode))failure netDown:(void(^)())netDown{
    NSDictionary *params = @{
                             @"id" : iphone_ID,
                             };
    [[Http sharedInstance] requestForMethod:POST Url:MYY_identify_URL withParams:params completion:^(id data, NSError *error) {
        if (data) {
            
            int  nRet = [[data objectForKey:@"status"] intValue];
            NSString *dataStr;
            NSString *dataArrStr=data[@"data"];
            if (nRet == 1) {
                success(dataArrStr);
            }
            else {
                dataStr= [data objectForKey:@"message"];
                failure( dataStr);
                
            }
            
        }else{
            failure( @"网络出错!!");

        }
        
        
    }];
}

- (void)boss:(void(^)(MYXbossModel *MYXbossMod))success
     failure:(void(^)(NSString *  errorCode))failure
     netDown:(void(^)())netDown
        page:(NSString *)page
        size:(NSString *)size{
    NSDictionary *paradic = @{
                              @"page":page,
                              @"size":size
                              };
    [[Http sharedInstance] requestForMethod:GET Url:MYX_boss_URL withParams:paradic completion:^(id data, NSError *error) {
        if (data) {
            
            int  nRet = [[data objectForKey:@"status"] intValue];
            NSString *dataStr;
            
            if (nRet == 1) {
                MYXbossModel *MYXbossMod = [MYXbossModel mj_objectWithKeyValues:data[@"data"]];
                success(MYXbossMod);
            }else {
                dataStr= [data objectForKey:@"message"];
                failure( dataStr);
                
            }
            
        }else{
            failure( @"网络出错!!");

        }
        
        
    }];
}
/**
 添加boss手机号
 
 @param bossPhone boss的手机号码
 @param result 返回结果
 */
- (void)addMyBossWithPhone:(NSString *)bossPhone
                withResult:(StateBlock)result{
    [[Http sharedInstance] uploadDataWithUrl:MYX_Add_BossPhone withParams:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        //  [formData appendPartWithFormData:[is_match dataUsingEncoding:NSUTF8StringEncoding]name:@"is_match"];
        [formData appendPartWithFormData:[bossPhone dataUsingEncoding:NSUTF8StringEncoding] name:@"fphone"];
    } completion:^(id data, NSError *error) {
        if (data) {
            NSString *message = data[@"message"];
            if ([data[@"status"] intValue] == 1) {
                result(YES,message);
            }else{
                result(NO,message);
            }
            
        }else {
            result(NO,@"网络出错！！");
        }
    }];
}
- (void)success:(void(^)(NSString *dataStr))success failure:(void(^)(NSString *  errorCode))failure netDown:(void(^)())netDown{
    [[Http sharedInstance] requestForMethod:GET Url:MYX_usefrozenmoney_URL withParams:nil completion:^(id data, NSError *error) {
        if (data) {
            
            int  nRet = [[data objectForKey:@"status"] intValue];
            NSString *dataStr=[data objectForKey:@"data"];
            
            if (nRet == 1) {
                success(dataStr);
            }
            else {
                dataStr= [data objectForKey:@"message"];
                failure( dataStr);
                
            }
            
        }else{
            failure( @"网络出错!!");

        }
        
        
    }];
}

- (void)randtags:(void(^)(NSArray *randtagsListArray))success failure:(void(^)(NSString *  errorCode))failure netDown:(void(^)())netDown{
    [[Http sharedInstance] requestForMethod:GET Url:MYY_randtags_URL withParams:nil completion:^(id data, NSError *error) {
        if (data) {
            
            int  nRet = [[data objectForKey:@"status"] intValue];
            NSString *dataStr;
            NSArray *array;
            if (nRet == 1) {
                
                if((NSNull *)data[@"data"]== [NSNull null])
                {
                    // return;
                }else{
                    array = data[@"data"];
                }
                success(array);
            }
            else {
                dataStr= [data objectForKey:@"message"];
                failure( dataStr);
                
            }
            
        }
        
        
    }];
}
- (void)PageIndex:(int)PageIndex usefrozenmoneyList:(void(^)(NSArray *usefrozenmoneyListArray))success failure:(void(^)(NSString *  errorCode))failure netDown:(void(^)())netDown{
    
    NSDictionary *param = @{
                            @"page":@(PageIndex),
                            };
    
    [[Http sharedInstance] requestForMethod:GET Url:MYX_bossmoneylist_URL withParams:param completion:^(id data, NSError *error) {
        if (data) {
            
            int  nRet = [[data objectForKey:@"status"] intValue];
            NSString *dataStr;
            NSArray *array;
            if (nRet == 1) {
                
                if((NSNull *)data[@"data"]== [NSNull null])
                {
                    // return;
                }else{
                    array = [MYX_Bossshouyi_listModel mj_objectArrayWithKeyValuesArray:data[@"data"]];
                }
                success(array);
            }
            else {
                dataStr= [data objectForKey:@"message"];
                failure( dataStr);
                
            }
            
        }
        
        
    }];
    
}

- (void)phone:(NSString *)phone code:(NSString *)code password:(NSString *)password success:(void(^)(MYY_User *user))success failure:(void(^)(NSString *  errorCode))failure netDown:(void(^)())netDown{
    NSDictionary *params;
    if (code.length>0) {
        params= @{
                  @"phone" : phone,
                  @"password" : password,
                  @"code" : code,
                  };
    }else{
        params= @{
                  @"phone" : phone,
                  @"password" : password,
                  };
    }
    
    [[Http sharedInstance] requestForMethod:POST Url:MYX_forget_URL withParams:params completion:^(id data, NSError *error) {
        if (data) {
            
            int  nRet = [[data objectForKey:@"status"] intValue];
            NSString *dataStr;
            
            if (nRet == 1) {
                MYY_User *userd = [[MYY_User alloc]init];
                userd.token             = data[@"data"][@"token"];
                userd.imtoken             = data[@"data"][@"imtoken"];
                userd.accid             = data[@"data"][@"accid"];
                userd.isLogin = YES;
                [userd save];
                success(userd);
            }
            else {
                dataStr= [data objectForKey:@"message"];
                failure( dataStr);
                
            }
            
        }
        
    }];
}
- (void)ismatch:(NSString *)is_match success:(void(^)(NSString *dataStr))success failure:(void(^)(NSString *  errorCode))failure netDown:(void(^)())netDown{
    
    [[Http sharedInstance] uploadDataWithUrl:MYX_ismatch_URL withParams:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        [formData appendPartWithFormData:[is_match dataUsingEncoding:NSUTF8StringEncoding]name:@"is_match"];
    } completion:^(id data, NSError *error) {
        NSString *dataStr;
        if (data) {
            int  nRet = [[data objectForKey:@"status"] intValue];
            if (nRet == 1) {
                if ([data[@"data"] isKindOfClass:[NSString class]]) {
                    NSString *dataArrStr=data[@"data"];
                    success(dataArrStr);
                }
                
            }
            else {
                dataStr= [data objectForKey:@"message"];
                failure( dataStr);
                
            }
            
        }else {
            dataStr= [data objectForKey:@"message"];
            failure( dataStr);
            
        }
        
        
    }];
    
}
- (void)findmatch:(NSString *)phones success:(void(^)(NSArray *findmatchListArray))success failure:(void(^)(NSString *  errorCode))failure netDown:(void(^)())netDown{
    [[Http sharedInstance] uploadDataWithUrl:MYX_findmatch_URL withParams:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        [formData appendPartWithFormData:[phones dataUsingEncoding:NSUTF8StringEncoding]name:@"phones"];
    } completion:^(id data, NSError *error) {
        if (data) {
            
            int  nRet = [[data objectForKey:@"status"] intValue];
            NSString *dataStr;
            NSArray *array;
            if (nRet == 1) {
                
                if((NSNull *)data[@"data"]== [NSNull null])
                {
                    // return;
                }else{
                    array = [MYXfindmatchModel mj_objectArrayWithKeyValuesArray:data[@"data"]];
                }
                success(array);
            }
            else {
                dataStr= [data objectForKey:@"message"];
                failure( dataStr);
                
            }
        }
        
        
    }];
}

- (void)setpaypwd:(NSString *)phone code:(NSString *)code paypassword:(NSString *)paypassword success:(void(^)(NSString *dataStr))success failure:(void(^)(NSString *  errorCode))failure netDown:(void(^)())netDown{
    [[Http sharedInstance] uploadDataWithUrl:MYX_setpaypwd_URL withParams:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        [formData appendPartWithFormData:[phone dataUsingEncoding:NSUTF8StringEncoding]name:@"phone"];
        [formData appendPartWithFormData:[code dataUsingEncoding:NSUTF8StringEncoding]name:@"code"];
        [formData appendPartWithFormData:[paypassword dataUsingEncoding:NSUTF8StringEncoding]name:@"paypassword"];
    } completion:^(id data, NSError *error) {
        NSString *dataStr;
        if (data) {
            
            int  nRet = [[data objectForKey:@"status"] intValue];
            if (nRet == 1) {
                    NSString *dataArrStr=data[@"data"][@"paypassword"];
                [MYXMemberMdel sharedInstance].userinfo.paypassword = dataArrStr;
                [[MYXMemberMdel sharedInstance] save];
                    success(dataArrStr);
            }
            else {
                dataStr= [data objectForKey:@"message"];
                failure( dataStr);
                
            }
            
        }else {
            //dataStr= [data objectForKey:@"message"];
            failure( @"请求错误");
        }
        
        
    }];
}

- (void)myblacklist:(int)PageIndex success:(void(^)(NSArray *blacklistArray))success failure:(void(^)(NSString *  errorCode))failure netDown:(void(^)())netDown{
    NSDictionary *param = @{
                            @"page":@(PageIndex),
                            };
    
    [[Http sharedInstance] requestForMethod:GET Url:MYX_bossmoneylist_URL withParams:param completion:^(id data, NSError *error) {
        if (data) {
            
            int  nRet = [[data objectForKey:@"status"] intValue];
            NSString *dataStr;
            NSArray *array;
            if (nRet == 1) {
                
                if((NSNull *)data[@"data"]== [NSNull null])
                {
                    // return;
                }else{
                    array = [MYX_Bossshouyi_listModel mj_objectArrayWithKeyValuesArray:data[@"data"]];
                }
                success(array);
            }
            else {
                dataStr= [data objectForKey:@"message"];
                failure( dataStr);
                
            }
            
        }
        
        
    }];
}
/**
 发红包
 
 @param lat 纬度
 @param lon 经度
 @param title 红包标题
 @param content 红包内容
 @param file 红包附件
 @param is_normal 是否是普通红包
 @param sex 性别区分
 @param rcount 红包个数
 @param money 金额
 @param radius 半径
 @param paypassword 支付密码
 @param result 返回结果
 @param errorResult 错误返回
 */
- (void)postLuckyMoneyWithlatitude:(NSString *)lat
                         longitude:(NSString *)lon
                             title:(NSString *)title
                           content:(NSString *)content
                              file:(NSString *)file
                         is_normal:(NSString *)is_normal
                               sex:(NSString *)sex
                            rcount:(NSString *)rcount
                             money:(NSString *)money
                            radius:(NSString *)radius
                       paypassword:(NSString *)paypassword
                         ticket_id:(NSString *)ticket_id
                        withResult:(StateBlock)result
                       errorResult:(ErrorBlock)errorResult{
    NSDictionary *para = @{@"latitude":lat,
                           @"longitude":lon,
                           @"title":title,
                           @"content":content,
                           @"file":file,
                           @"is_normal":is_normal,
                           @"sex":sex,
                           @"rcount":rcount,
                           @"money":money,
                           @"radius":radius,
                           @"paypassword":paypassword
                           };
    [[Http sharedInstance] uploadDataWithUrl:PostLuckyMoneyUrl withParams:para constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
       [formData appendPartWithFormData:[lat dataUsingEncoding:NSUTF8StringEncoding]name:@"latitude"];
        [formData appendPartWithFormData:[lon dataUsingEncoding:NSUTF8StringEncoding]name:@"longitude"];
         [formData appendPartWithFormData:[title dataUsingEncoding:NSUTF8StringEncoding]name:@"title"];
         [formData appendPartWithFormData:[content dataUsingEncoding:NSUTF8StringEncoding]name:@"content"];
        [formData appendPartWithFormData:[file dataUsingEncoding:NSUTF8StringEncoding]name:@"file"];
        [formData appendPartWithFormData:[rcount dataUsingEncoding:NSUTF8StringEncoding]name:@"rcount"];
        [formData appendPartWithFormData:[money dataUsingEncoding:NSUTF8StringEncoding]name:@"money"];
        [formData appendPartWithFormData:[radius dataUsingEncoding:NSUTF8StringEncoding]name:@"radius"];
        [formData appendPartWithFormData:[is_normal dataUsingEncoding:NSUTF8StringEncoding]name:@"is_normal"];
        [formData appendPartWithFormData:[sex dataUsingEncoding:NSUTF8StringEncoding]name:@"sex"];
        [formData appendPartWithFormData:[paypassword dataUsingEncoding:NSUTF8StringEncoding]name:@"paypassword"];
        [formData appendPartWithFormData:[ticket_id dataUsingEncoding:NSUTF8StringEncoding] name:@"ticket_id"];
        
        
    } completion:^(id data, NSError *error) {
        if (data) {
            NSString *message = data[@"message"];
            if ([data[@"status"] intValue] == 1) {
                result(YES,message);
            }else{
                result(NO,message);
            }
        }else{
            result(NO,@"请求出错");
        }
        
    }];
//    [[Http sharedInstance] requestForMethod:POST Url:PostLuckyMoneyUrl withParams:para completion:^(id data, NSError *error) {
//        result(YES,@"");
//        
//    }];
}


/**
 资料卡

 @param userID 用户id
 @param result 返回结果
 @param errorResult 失败结果
 */
-(void)otheruserinfo:(NSString *)userID
          withResult:(ModelBlock)result
         errorResult:(ErrorBlock)errorResult{
    NSDictionary *param = @{
                            @"id":userID,
                            };
    [[Http sharedInstance] requestForMethod:GET Url:MYX_otheruserinfo_URL withParams:param completion:^(id data, NSError *error) {
            if (data) {
                NSString *message = data[@"message"];
                if ([data[@"status"] intValue] == 1) {
                    
                 MYXotheruserinfoModel *MYXotheruserinfoM = [MYXotheruserinfoModel mj_objectWithKeyValues:data[@"data"]];
                    
                result(YES, message, MYXotheruserinfoM);
                    
                }else{
                      result(NO,message,nil);
                }
                
            }else{
                      result(NO,@"请求出错",nil);
            }
    }];
}

/**
 资料卡列表
 
 @param userID 用户id
 @param result 返回结果
 @param errorResult 错误返回
 */
-(void)otheruserinfoList:(NSString *)userID withResult:(ModelBlock)result errorResult:(ErrorBlock)errorResult{
    NSDictionary *param = @{
                            @"id":userID,
                            };
    [[Http sharedInstance] requestForMethod:GET Url:MYX_otheruserinfo_URL withParams:param completion:^(id data, NSError *error) {
        if (data) {
            NSString *message = data[@"message"];
            if ([data[@"status"] intValue] == 1) {
                
                MYXotherinfoListModel *MYXotheruserinfoMList = [MYXotherinfoListModel mj_objectWithKeyValues:data[@"data"][@"publish"]];
                
                result(YES, message, MYXotheruserinfoMList);
                
            }else{
                result(NO,message,nil);
            }
            
        }else{
            result(NO,@"请求出错",nil);
        }
    }];
}



/**
  我的发布
  
  @param PageIndex 多少页
  @param result 返回结果
  @param errorResult 返回错误
  */
- (void)mypublish:(int)PageIndex
       withResult:(ArrayBlock)result
      errorResult:(ErrorBlock)errorResult{
    NSDictionary *param = @{
                            @"page":@(PageIndex),
                            };
    [[Http sharedInstance] requestForMethod:GET Url:MYX_mypublisho_URL withParams:param completion:^(id data, NSError *error) {
        if (data) {
            NSArray *dicarray ;
            NSString *message = data[@"message"];
           if ([data[@"status"] intValue] == 1)  {
                dicarray = [MYXmypublishModel mj_objectArrayWithKeyValuesArray:data[@"data"][@"list1"]];
                result(YES,@"请求成功",dicarray);
            }else{
                result(NO,message,nil);
            }
            
        }else{
            errorResult(error);
        }
    }];
}

/**
 钱来钱往
 
 @param PageIndex 多少页
 @param result 返回结果
 @param errorResult 返回错误
 */

- (void)mymoneylog:(int)PageIndex
        withResult:(ArrayBlock)result
       errorResult:(ErrorBlock)errorResult{
    NSDictionary *param = @{
                            @"page":@(PageIndex),
                            };
    [[Http sharedInstance] requestForMethod:GET Url:MYX_mymoneylog_URL withParams:param completion:^(id data, NSError *error) {
        if (data) {
            NSArray *dicarray ;
            NSString *message = data[@"message"];
            if ([data[@"status"] intValue] == 1)  {
                dicarray = [MYCmymoneylogModel mj_objectArrayWithKeyValuesArray:data[@"data"]];
                result(YES,@"请求成功",dicarray);
            }else{
                result(NO,message,nil);
            }
            
        }else{
            errorResult(error);
        }
    }];
    
}

/**
  我的钱包

 @param result 返回结果
 @param errorResult 返回错误
 */
-(void)mymoney:(ModelBlock)result
   errorResult:(ErrorBlock)errorResult{
    [[Http sharedInstance] requestForMethod:GET Url:MYX_mymoney_URL withParams:nil completion:^(id data, NSError *error) {
        if (data) {
            NSString *message = data[@"message"];
            if ([data[@"status"] intValue] == 1) {
                
                MYXmymoneyModel *MYXmymoneyMod = [MYXmymoneyModel mj_objectWithKeyValues:data[@"data"]];
                
                result(YES, message, MYXmymoneyMod);
                
            }else{
                result(NO,message,nil);
            }
            
        }else{
            result(NO,@"请求出错",nil);
        }
        
        
    }];
}
/**
 获取热榜
 
 @param result 返回结果
 @param errorResult 错误结果
 */
- (void)getTopHotestListWithResult:(ArrayBlock)result
                       errorResult:(ErrorBlock)errorResult{
    
    [[Http sharedInstance] requestForMethod:GET Url:@"/board" withParams:nil completion:^(id data, NSError *error) {
        
//        //假数据模拟
//        NSString *pathfile = [[NSBundle mainBundle] pathForResource:@"toplist" ofType:@"json"];
//        NSData *toplistData = [NSData dataWithContentsOfFile:pathfile];
//        NSError *pathError = [[NSError alloc] init];
//        NSDictionary *dicdata = [NSJSONSerialization JSONObjectWithData:toplistData options:kNilOptions error:&pathError];
        if (data) {
            NSArray *dicarray = data[@"data"];
            NSString *message = data[@"message"];
           // NSString *status = data[@"status"];
            if ([data[@"status"] intValue] == 1) {
                NSMutableArray *modelArray = [NSMutableArray array];
                for (NSDictionary *dic in dicarray) {
                    NSError *error = nil;
                    TopHotestModel *model = [[TopHotestModel alloc] initWithDictionary:dic error:&error];
                    [modelArray addObject:model];
                }
                result(YES,@"请求成功",modelArray);
            }else{
                result(NO,message,nil);
            }
            
    }else{
            errorResult(error);
        }
        
    }];
}
#pragma mark - 获取红包券列表
- (void)getVochersListWithResult:(ArrayBlock)result
                     errorResult:(ErrorBlock)errorResult{
    [[Http sharedInstance] requestForMethod:GET Url:@"/myticketlist" withParams:nil completion:^(id data, NSError *error) {
        if (data) {
            NSString *message = data[@"message"];
            if ([data[@"status"] intValue] == 1) {
                NSMutableArray *modelArray = [NSMutableArray array];
                if ([data[@"data"] isKindOfClass:[NSArray class]]) {
                    for (NSDictionary *dic in data[@"data"]) {
                        NSError * error = nil;
                        VocherModel *vocherModel = [[VocherModel alloc] initWithDictionary:dic error:&error];
                        [modelArray addObject:vocherModel];
                    }
                    result(YES,message,modelArray);
                }else{
                    result(NO,@"没有红包券",nil);
                }
               
            }else{
                result(NO,message,nil);
            }

        }else{
            result(NO,@"请求出错",nil);
        }
        
    }];
}
/**
 充值支付接口
 
 @param payType 支付方式·
 @param money 支付金额
 @param result 结果
 @param errorResult 错误结果
 */
- (void)rechargeWithPayType:(NSString *)payType
                      money:(NSString *)money
                     result:(StateBlock)result
                errorResult:(ErrorBlock)errorResult{
    
    [[Http sharedInstance] uploadDataWithUrl:@"/recharge" withParams:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        [formData appendPartWithFormData:[payType dataUsingEncoding:NSUTF8StringEncoding]name:@"pay_name"];
        [formData appendPartWithFormData:[money dataUsingEncoding:NSUTF8StringEncoding]name:@"money"];
        
    } completion:^(id data, NSError *error) {
        if (data) {
            NSString *order = data[@"data"];
            NSString *appScheme = @"MYXAlijustPay";
            [ [AlipaySDK defaultService] payOrder:order fromScheme:appScheme callback:^(NSDictionary *resultDic) {

                NSString *showMsg = resultDic[@"result"][@"memo"];
                if ([resultDic[@"result"][@"resultStatus"] intValue] == 9000) {
                    result(YES,showMsg);
                }else{
                    result(NO,showMsg);
                }
                NSLog(@"reslut = %@",resultDic);
            }];
        }else {
            errorResult(error);
        }
        
        
    }];
}
/**
 获取投票列表
 
 @param page 页数
 @param size 每页个数
 @param result 返回结果
 @param errorResult 错误结果
 */
- (void)getVoteListWithPage:(NSString *)page
                       size:(NSString *)size
                     Result:(ArrayBlock)result errorResult:(ErrorBlock)errorResult{
    NSDictionary *paraDic = @{
                              @"page":page,
                              @"size":size
                              };
    [[Http sharedInstance] requestForMethod:GET Url:@"/votelist" withParams:paraDic completion:^(id data, NSError *error) {
        
        if (data) {
            NSString *message = data[@"message"];
            if ([data[@"status"] intValue] == 1) {
                NSMutableArray *modelArray = [NSMutableArray array];
                if (![data[@"data"] isKindOfClass:[NSArray class]] ) {
                    
                    result(NO,message,nil);
                    return ;
                }
               
            for (NSDictionary *dic in data[@"data"]) {
                        NSError * error = nil;
                        MYXVoteModel *votemodel = [[MYXVoteModel alloc] initWithDictionary:dic error:&error];
                        
                        [modelArray addObject:votemodel];
                    }
                    
                    result(YES,message,modelArray);

            }else{
                result(NO,message,nil);
            }
            
        }else{
            result(NO,@"请求出错",nil);
        }
    }];
}
/**
 投票
 
 @param result 投票结果
 */
- (void)voteWithVoteId:(NSString *)voteId
                Result:(StateBlock)result
           errorResult:(ErrorBlock)errorResult{
    NSDictionary *paradic = @{@"id":voteId};
    [[Http sharedInstance] requestForMethod:GET Url:@"/vote" withParams:paradic completion:^(id data, NSError *error) {
        if (data) {
            NSString *message = data[@"message"];
            if ([data[@"status"] intValue] == 1) {
                result(YES,message);
            }else{
                result(NO,message);
            }
        }else{
            errorResult(error);
        }
        
    }];
}
/**
 报名参加接口
 
 @param para 报名请求资料
 @param result 结果
 @param errorResult 错误结果
 */
- (void)applyActivityWithPara:(NSDictionary *)para
                       Result:(StateBlock)result
                  errorResult:(ErrorBlock)errorResult{
    [[Http sharedInstance] uploadDataWithUrl:@"/addvote" withParams:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        [formData appendPartWithFormData:[para[@"name"] dataUsingEncoding:NSUTF8StringEncoding]name:@"name"];
        [formData appendPartWithFormData:[para[@"age"] dataUsingEncoding:NSUTF8StringEncoding]name:@"age"];
        [formData appendPartWithFormData:[para[@"tel"] dataUsingEncoding:NSUTF8StringEncoding]name:@"tel"];
        [formData appendPartWithFormData:[para[@"image"] dataUsingEncoding:NSUTF8StringEncoding]name:@"image"];
        
    } completion:^(id data, NSError *error) {
        
        if (data) {
            NSString *message = data[@"message"];
            if ([data[@"status"] intValue] == 1) {
                result(YES,message);
            }else{
                result(NO,message);
            }
           
        }else {
            errorResult(error);
        }
        
        
    }];
}
/**
 投票报名搜索接口
 
 @param keyword 关键字
 @param result 返回结果
 @param errorResult 错误结果
 */
- (void)applyActivitySearchWithKeyWord:(NSString *)keyword
                            withResult:(ArrayBlock)result
                           errorResult:(ErrorBlock)errorResult{
    NSDictionary *para = @{
                           @"kw":keyword
                           };
    [[Http sharedInstance] requestForMethod:GET Url:@"/searchvotelist" withParams:para completion:^(id data, NSError *error) {
        NSString *message = data[@"message"];

        if (data) {
            NSMutableArray *modelArray = [NSMutableArray array];
            if (![data[@"data"] isKindOfClass:[NSArray class]] ) {
                
                result(NO,message,nil);
                return ;
            }
            
            for (NSDictionary *dic in data[@"data"]) {
                NSError * error = nil;
                MYXVoteModel *votemodel = [[MYXVoteModel alloc] initWithDictionary:dic error:&error];
                
                [modelArray addObject:votemodel];
            }
            
            result(YES,message,modelArray);
            
        }else{
            result(NO,message,nil);
        }
       
    }];
}
/**
 提现接口
 
 @param moneyCount 提现金额
 @param payname 提现到账平台
 @param payid 账号
 @param paypassword 支付密码
 @param result 返回结果
 */
- (void)cashMoneyWithMoneyCount:(NSString *)moneyCount
                        payname:(NSString *)payname
                          payid:(NSString *)payid
                    paypassword:(NSString *)paypassword
                     withResult:(StateBlock)result{
    [[Http sharedInstance] uploadDataWithUrl:@"/transtoaccount" withParams:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        [formData appendPartWithFormData:[moneyCount dataUsingEncoding:NSUTF8StringEncoding]name:@"money"];
        [formData appendPartWithFormData:[payname dataUsingEncoding:NSUTF8StringEncoding]name:@"pay_name"];
        [formData appendPartWithFormData:[payid dataUsingEncoding:NSUTF8StringEncoding]name:@"pay_id"];
        [formData appendPartWithFormData:[paypassword dataUsingEncoding:NSUTF8StringEncoding]name:@"paypassword"];
        
    } completion:^(id data, NSError *error) {
        
        if (data) {
            NSString *message = data[@"message"];
            if ([data[@"status"] intValue] == 1) {
                result(YES,message);
            }else{
                result(NO,message);
            }
            
        }else {
            result(NO,@"提现异常");
        }
        
        
    }];
}
/**
 获取第一次红包体验券
 
 @param result 返回结果
 */
- (void)getFirstTimeTicketWithResult:(StateBlock)result{
    [[Http sharedInstance] requestForMethod:GET Url:@"/firstticket" withParams:nil completion:^(id data, NSError *error) {
        if (data) {
            NSString *message = data[@"message"];
            if ([data[@"status"] intValue] == 1) {
                result(YES,message);
            }else{
                result(NO,message);
            }
            
        }else {
            result(NO,@"领取出错");
        }
    }];
}
- (void)getMYXHomepageVochersWithlat:(NSString *)lat
                                 lon:(NSString *)lon
                                 pid:(NSString *)pid
                              Result:(StateBlock)result{
    [[Http sharedInstance] uploadDataWithUrl:@"/gettickt" withParams:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        [formData appendPartWithFormData:[lat dataUsingEncoding:NSUTF8StringEncoding]name:@"lat"];
        [formData appendPartWithFormData:[lon dataUsingEncoding:NSUTF8StringEncoding]name:@"lng"];
        [formData appendPartWithFormData:[pid dataUsingEncoding:NSUTF8StringEncoding]name:@"pid"];
        
    } completion:^(id data, NSError *error) {
        
        if (data) {
            NSString *message = data[@"message"];
            if ([data[@"status"] intValue] == 1) {
                result(YES,message);
            }else{
                result(NO,message);
            }
            
        }else {
            result(NO,@"请求异常");
        }
        
        
    }];
}
/**
 发送红包券
 
 @param lat 纬度
 @param lon 精度
 @param count 数量
 @param money 减免金额
 @param result 返回结果
 */
- (void)postVocherWithLat:(NSString *)lat
                      lon:(NSString *)lon
                    count:(NSString *)count
                    money:(NSString *)money
               withResult:(StateBlock)result{
    [[Http sharedInstance] uploadDataWithUrl:@"/ticket" withParams:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        [formData appendPartWithFormData:[lat dataUsingEncoding:NSUTF8StringEncoding]name:@"latitude"];
        [formData appendPartWithFormData:[lon dataUsingEncoding:NSUTF8StringEncoding]name:@"longitude"];
        [formData appendPartWithFormData:[count dataUsingEncoding:NSUTF8StringEncoding]name:@"rcount"];
        [formData appendPartWithFormData:[money dataUsingEncoding:NSUTF8StringEncoding] name:@"smoney"];
        
    } completion:^(id data, NSError *error) {
        
        if (data) {
            NSString *message = data[@"message"];
            if ([data[@"status"] intValue] == 1) {
                result(YES,message);
            }else{
                result(NO,message);
            }
            
        }else {
            result(NO,@"请求异常");
        }
        
        
    }];
}
/**
 反馈接口
 
 @param content 反馈内容
 @param result 反馈接口返回结果
 */
- (void)postQuestionWithContent:(NSString *)content
                     withResult:(StateBlock)result{
    NSDictionary *dicpara = @{
                              @"content":content
                              };
    [[Http sharedInstance] uploadDataWithUrl:@"/addcallback" withParams:dicpara constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        [formData appendPartWithFormData:[content dataUsingEncoding:NSUTF8StringEncoding] name:@"content"];
    } completion:^(id data, NSError *error) {
        if (data) {
            NSString *message = data[@"message"];
            if ([data[@"status"] intValue] == 1) {
                result(YES,message);
            }else{
                result(NO,message);
            }
            
        }else {
            result(NO,@"请求异常");
        }
    }];
}
- (void)checkVersionWithResult:(StateBlock)result{
    NSDictionary *param = @{
                            @"apptype":@"ios"
                            };
    [[Http sharedInstance] requestForMethod:GET Url:@"/getversion" withParams:param completion:^(id data, NSError *error) {
        if (data) {
            NSString *message = data[@"data"];
            if ([data[@"status"] intValue] == 1) {
                result(YES,message);
            }
            
        }
    }];
}
/**
 点击进入回复详情
 
 @param redPocketId 红包的id
 @param recommendManId 评论人的id
 @param commendListResult 评论列表
 */
- (void)clickToCommendListWithPage:(NSString *)page
                              size:(NSString *)size
                       RedPacketId:(NSString *)redPocketId
                    recommendManId:(NSString *)recommendManId
                            result:(ArrayBlock)commendListResult{
    NSDictionary *parameter = @{
                                @"id":redPocketId,
                                @"uid":recommendManId,
                                @"page":page,
                                @"size":size

                                };
    [[Http sharedInstance] requestForMethod:GET Url:@"/redmessagelist" withParams:parameter completion:^(id data, NSError *error) {
        if (data) {
            NSString *message = data[@"data"];
            NSMutableArray *modelArray = [NSMutableArray array];
            if ([data[@"status"] intValue] == 1) {
                NSError * error = nil;
                NSDictionary *ondict = data[@"data"][@"one"];
                CommentModel *onecommentModel = [[CommentModel alloc] initWithDictionary:ondict error:&error];
                [modelArray addObject:onecommentModel];
                for (NSDictionary *dic in data[@"data"][@"two"]) {
                    CommentModel *commentModel = [[CommentModel alloc] initWithDictionary:dic error:&error];
                    [modelArray addObject:commentModel];
                }
                commendListResult(YES,message,modelArray);
          
            }else{
                ShowSVProgressErrorMessage(message);
            }
            
        }
    }];
}
- (void)leaveMoreContentWithLuckyMoneyId:(NSString *)luckyMoneyId
                                 content:(NSString *)content
                              to_user_id:(NSString *)to_user_id
                              rp_user_id:(NSString *)rp_user_id
                                  result:(StateBlock)result{
    NSDictionary *dicpara = @{
                              @"rid":luckyMoneyId,
                              @"content":content,
                              @"user_id":to_user_id,
                              @"rp_user_id":rp_user_id
                              };
    [[Http sharedInstance] uploadDataWithUrl:@"/remessage2" withParams:dicpara constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        [formData appendPartWithFormData:[luckyMoneyId dataUsingEncoding:NSUTF8StringEncoding] name:@"rid"];
        [formData appendPartWithFormData:[content dataUsingEncoding:NSUTF8StringEncoding] name:@"content"];
        [formData appendPartWithFormData:[to_user_id dataUsingEncoding:NSUTF8StringEncoding] name:@"user_id"];
        [formData appendPartWithFormData:[rp_user_id dataUsingEncoding:NSUTF8StringEncoding] name:@"rp_user_id"];
    } completion:^(id data, NSError *error) {
        if (data) {
            NSString *message = data[@"message"];
            if ([data[@"status"] intValue] == 1) {
                result(YES,message);
            }else{
                result(NO,message);
            }
            
        }else {
            result(NO,@"请求异常");
        }
    }];
}
- (void)getNoticesWitResult:(ArrayBlock)result {
    [[Http sharedInstance] requestForMethod:GET Url:@"/getindexnews" withParams:nil completion:^(id data, NSError *error) {
        if (data) {
            NSString *message = data[@"message"];
            NSMutableArray *modelArray = [NSMutableArray array];
            if ([data[@"status"] intValue] == 1) {
              
                NSError * error = nil;
                for (NSDictionary *noticeDic in data[@"data"]) {
                    //NSString *content = noticeDic[@"content"];
                    NoticeModel *noticeModel = [[NoticeModel alloc] initWithDictionary:noticeDic error:&error];
                    [modelArray addObject:noticeModel];
                }
                result(YES,message,modelArray);
//                NSDictionary *ondict = data[@"data"][@"one"];
//                CommentModel *onecommentModel = [[CommentModel alloc] initWithDictionary:ondict error:&error];
//                [modelArray addObject:onecommentModel];
//                for (NSDictionary *dic in data[@"data"][@"two"]) {
//                    CommentModel *commentModel = [[CommentModel alloc] initWithDictionary:dic error:&error];
//                    [modelArray addObject:commentModel];
//                }
//  commendListResult(YES,message,modelArray);
                
            }else{
               // ShowSVProgressErrorMessage(message);
            }
            
        }
    }];
}
@end
